#include "Button.hpp"
#include "ContainerControl.hpp"
#include <map>
#include "Application.hpp"
using namespace NAMESPACENAME;
extern std::map<HWND, Control*> __mapWindows;
Button::Button(const Rectangle& rect, String title, ContainerControl* parent) :
	Control(parent)
{
	auto p(title.UnsafeGetString());
	hWnd = CreateWindowExW(
		0,
		L"Button",
		p,
		WS_CHILD,
		rect.x,
		rect.y,
		rect.width,
		rect.height,
		parent->WindowHandle(),
		GetId(parent),
		Application::GetInstance(),
		nullptr
	);
	delete[] p;
	if (hWnd)
		__mapWindows.emplace(std::make_pair(hWnd, this));
	else
		throw std::exception("Create Button Failed!", 0);
}
void Button::OnDestroy()
{
}
void Button::OnClose()
{
}
void Button::OnNcPaint(HRGN hRgn)
{
}
void Button::OnCommand(UINT message, UINT id, Control* control)
{
	switch (message)
	{
	case BN_CLICKED:
	{
		EventArgs e;
		onMouseClick(this, e);
	}
	break;
	default:
		break;
	}
}
void Button::OnLoad()
{
	::SetWindowLongPtrW(hWnd, GWL_STYLE, ::GetWindowLongPtrW(hWnd, GWL_STYLE) | WS_VISIBLE);
}
void Button::OnUnLoad()
{
	::SetWindowLongPtrW(hWnd, GWL_STYLE, ::GetWindowLongPtrW(hWnd, GWL_STYLE) & ~WS_VISIBLE);
}
void Button::OnPaint()
{
}